package com.leo.ktvplayer.pay;

import android.os.Handler;
import android.os.Message;
import android.view.View;

import com.leo.ktvplayer.base.App;

/**
 *
 */
public class BasePaymentThread extends Thread {
    public void tryStopThread(){
        isrunning = false;
    }

    protected boolean isrunning = true;
    protected OnPaymentFailed onPaymentFailed;
    protected OnPaymentSuccess onPaymentSuccess;
    protected OnPaymentUrlCallBack onPaymentUrlCallBack;

    protected static final int ON_SUCCESS = 0;
    protected static final int ON_FAILED = 1;
    protected static final int ON_URL_CALL = 2;

    protected String orderId;
    protected double money;

    public void setOrderId(String orderId){
        this.orderId = orderId;
    }

    public void setMoney(double money) {
        this.money = money;
    }

    protected Handler handler = new Handler(App.getInstance().getMainLooper()){
        public void handleMessage(Message message) {
            if (message.what == ON_URL_CALL) {
                onPaymentUrlCallBack.onCall((String) message.obj);
            } else if (message.what == ON_FAILED) {
                onPaymentFailed.onFailed();
            } else if (message.what ==  ON_SUCCESS){
                onPaymentSuccess.onSuccess();
            }
        }

    };

    public void setOnPaymentFailed(OnPaymentFailed onPaymentFailed){
        this.onPaymentFailed = onPaymentFailed;

    }

    public void setOnPaymentSuccess(OnPaymentSuccess onPaymentSuccess){
        this.onPaymentSuccess = onPaymentSuccess;
    }

    public void setOnPaymentUrlCallBack(OnPaymentUrlCallBack onPaymentUrlCallBack) {
        this.onPaymentUrlCallBack = onPaymentUrlCallBack;
    }
}
